package com.yami.shop.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.Member;
import com.yami.shop.bean.model.Rebate;
import com.yami.shop.bean.model.ShopMember;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.util.SecurityUtils;
import com.yami.shop.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/admin/shopMember")
public class MemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<ShopMember>> page(ShopMember shopMember, PageParam<ShopMember> page) {
        Long  shopId = SecurityUtils.getSysUser().getShopId();
        shopMember.setShopId(shopId);
        IPage<ShopMember> userIPage = memberService.pagebyMember(page,shopMember);
        return ResponseEntity.ok(userIPage);
    }

    /**
     * 获取会员详情信息
     */
    @GetMapping("/getMemberInformation")
    public ResponseEntity<ShopMember> getMemberInformation(Long memberId){
        ShopMember shopMember = memberService.getMember(memberId);
        return ResponseEntity.ok(shopMember);
    }

    /**
     * 删除会员
     */
    @PutMapping("/updateStatus")
    public ResponseEntity<Void> updateStatus( Long memberId){
        memberService.updateStatus(memberId);
        return ResponseEntity.ok().build();
    }

    /**
     * 恢复会员
     */
    @PutMapping("/restoreMember")
    public ResponseEntity<Void> restoreMember(Long memberId){
        memberService.restoreMember(memberId);
        return ResponseEntity.ok().build();
    }
}
